﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace JQueryWidget.WidgetWeb.Modules
{
    public partial class ContentWidget : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShowPanel.Visible = true;
            EditPanel.Visible = false;
            ShowTestLabel.Text = GetText();
        }

        public void Edit()
        {
            EditPanel.Visible = true;
            ShowPanel.Visible = false;
            DataTextBox.Text = GetText();
        }

        public void Save()
        {
            ShowPanel.Visible = true;
            EditPanel.Visible = false;
            ShowTestLabel.Text = DataTextBox.Text;
            SaveText(DataTextBox.Text);
        }

        protected string GetText()
        {
            string text = string.Empty;
            using (StreamReader sReader = new StreamReader(@"E:\a.txt"))
            {
                 text = sReader.ReadToEnd();
            }
            return text;
        }

        protected void SaveText(string text)
        {
            using (StreamWriter sWriter = new StreamWriter(@"E:\a.txt", false))
            {
                sWriter.Write(text);
                sWriter.Close();
            }
        }
    }
}